<template>
    <view>
		<view class="left" @tap.stop="back">
			<image src="@/static/home/left.png" mode=""></image>
		</view>
		<view class="textName">
			附件预览
		</view>
        <view id="web-info" style="width: 100%;height: 100%;">
            <web-view   v-if="!isShow" :src="pdfUrl"></web-view>
			<view class="" style="margin-top: 200rpx;font-size: 40rpx;" v-show="isShow">
				暂无附件
			</view>
        </view>
    </view>
</template>

<script>
	import baseUrl from "@/api/base.js"
    export default {
        name: 'viewPdf',
        data() {
            return {
                isShow: false,
                pdfUrl: '',
                env: '',
				versionId:''
            }
        },

        onLoad(params) {
			// this.versionId = '1681503758122790913'
			this.versionId = params.versionId
			console.log(this.versionId,'this.versionId',baseUrl)
            // let option = decodeURIComponent(params.url);
            // this.pdfUrl= baseUrl.apiUrl+`/profile/upload/pdf.pdf`  
			this.getVersionId()
			// uni.getSystemInfo({
			//     success: function (res) {
			//         that.setData({
			//           systemInfo: res
			//         });
			// 		console.log(res,'annexUrl')
			//       }
			// })

        },
		mounted() {
			// this.getFile2()
		},
        methods: {
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
			getVersionId(){
				console.log('我出法抗')
				let that = this
				that.$api.versionId(that.versionId).then(res => {
					if(res.data.data.annexUrl == null)this.isShow = true
					that.pdfUrl = baseUrl.apiUrl+ res.data.data.annexUrl 
					console.log(that.pdfUrl);
				})
			},
            getFile2(url) {
                let that = this;
                // uni.showLoading({
                //     title: '加载中',
                //     mask: true
                // });
                uni.downloadFile({
                   url: url,
                   header: {
                   	'Accept': 'application/json',
                   	'Content-Type': 'application/json',
                   },
                    success: (result) => {
                    	var tempFilePath = result.tempFilePath
                    	//这里的`/hybrid/html/web/viewer.html`是pdf.js放在项目里的地址
                    	//h5页面这样写即可
                    	that.pdfUrl = `/hybrid/html/web/viewer.html?file=${tempFilePath}`;
                    	//app需要特殊处理一下才行
                    	let fileUrl = plus.io.convertLocalFileSystemURL(tempFilePath)
                    	that.pdfUrl = `/hybrid/html/web/viewer.html?file=${fileUrl}`;
                    	uni.hideLoading();
                    },
                    fail: function(res) {
                    	uni.hideLoading();
                    	uni.showToast({
                    		title: '文件下载失败，请重试',
                    		icon: "none",
                    		mask: true,
                    		position: "center"
                    	})
                    },
                })
            },
        }
    }
</script>
<style lang="scss" scoped>
    #web-info {
        width: 100%;
        height: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
    }
	.left {
		top: 3.8%;
		left: 4%;
		position: fixed;
	
		image {
			width: 21rpx;
			height: 34rpx;
		}
	}
	.textName{
		top: 3%;
		left: 41%;
		position: fixed;
		color: #000;
		font-size: 34rpx;
	}
</style>
